package com.huadi.firematerialident.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.w3c.dom.ls.LSException;

import java.util.List;
import java.util.Map;

import static com.fasterxml.jackson.databind.type.LogicalType.Map;

@Repository
public class UserDaoImpl implements UserDao{
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public void addUser(String username, String password, String role) {
        jdbcTemplate.update("update user set username=?,password=?,role=? where id=1",username,password,role);
    }

    @Override
    public void delUser() {
        jdbcTemplate.update("update user set username=null,password=null,role=null where id=1");
    }

    @Override
    public String getRole() {
        String sql = "select role from user where id=1";
        List<Map<String, Object>> map = jdbcTemplate.queryForList(sql);
        return (String) map.get(0).get("role");
    }

    @Override
    public String getUsername() {
        return (String)jdbcTemplate.queryForList("select username from user where id = 1").get(0).get("username");
    }
}

